<?php

/**
 * ResMania Module Class
 *
 * @access 	public
 * @author      Rob
 * @copyright	ResMania 2009-present all rights reserved.
 * @version	1.0
 * @link	http://docs.resmania.com/index.php/LiveChat_Module
 * @since  	09-2010
 */
class RM_Module_LiveChat extends RM_Module implements RM_Unit_Details_Tray_Interface, RM_Unit_List_Tray_Interface {

    public function __construct() {
        $this->name = 'LiveChat';
    }

    public function getConfigNode() {
        return null;
    }

    /**
     * get the HTML for the main unit info page, system tray icon
     *
     * @param RM_Unit_Row $unit
     * @return string   html string
     */
    public function getHTML(RM_Unit_Row $unit) {

        $daoConfig = new RM_LiveChatConfig();
        $config = $daoConfig->getConfig()->toArray();
        
        if ((int)$config[0]['enable_moduletray_icon'] === 1){
            $row = $daoConfig->getStatus()->toArray();
            if (!empty($row)) {
                $icon = RM_Environment::getConnector()->getRootURL() . 'RM/userdata/modules/LiveChat/images/tray_icon_online.gif';
            } else {
                $icon = RM_Environment::getConnector()->getRootURL() . 'RM/userdata/modules/LiveChat/images/tray_icon_offline.gif';
            }
            return "<a href='javascript:void(0)' onclick=\"RM_doShadowBox('" . RM_Environment::getInstance()->getRouter()->_('LiveChat', 'chat', array("page" => "chat.phtml")) . "', '', 620, 350, 'iframe' )\" ><img src='" . $icon . "' border='0'></a>";
        }
    }

    /**
     * get the HTML for the main unit list page, system tray icon
     *
     * @param RM_Unit_Row $unit
     * @return string   html string
     */
    public function getListHTML(RM_Unit_Row $unit) {

        $daoConfig = new RM_LiveChatConfig();
        $config = $daoConfig->getConfig()->toArray();

        if ((int)$config[0]['enable_moduletray_icon']===1){
            $row = $daoConfig->getStatus()->toArray();
            if (!empty($row)) {
                $icon = RM_Environment::getConnector()->getRootURL() . 'RM/userdata/modules/LiveChat/images/tray_icon_online.gif';
            } else {
                $icon = RM_Environment::getConnector()->getRootURL() . 'RM/userdata/modules/LiveChat/images/tray_icon_offline.gif';
            }
            return "<a href='javascript:void(0)' onclick=\"RM_doShadowBox('" . RM_Environment::getInstance()->getRouter()->_('LiveChat', 'chat', array("page" => "chat.phtml")) . "', '', 620, 350, 'iframe' )\" ><img width='30px' height='30px' src='" . $icon . "' border='0'></a>";
        }
    }

}
